function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function  dateDiff(sDate1,  sDate2) {    //sDate1和sDate2是2006-12-18格式    
  var  aDate,  oDate1,  oDate2,  iDays    
  aDate  = sDate1.split("-")    
  oDate1 = new  Date(aDate[1]  +  '/'  +  aDate[2]  +  '/'  +  aDate[0])    //转换为12/18/2006格式    
  aDate  = sDate2.split("-")    
  oDate2 = new  Date(aDate[1]  +  '/'  +  aDate[2]  +  '/'  +  aDate[0])    
  iDays  = parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24)    //把相差的毫秒数转换为天数   
  return  iDays + 1   
}

module.exports = {
  formatTime: formatTime,
  dateDiff: dateDiff
}
